//
//  SettingController.m
//  ChickenA
//
//  Created by 韦显光 on 2018/7/17.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "SettingController.h"
#import "SettingCell.h"
#import "ClearCacheTool.h"
#import "IDAuthViewController.h"

@interface SettingController ()
{
    NSArray*dataary;
}
@end

@implementation SettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    dataary=@[@[@"实名认证",@"更换手机号",@"修改密码",@"关于我们",@"清除缓存"],@[@"退出登录"]];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 返回分组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return dataary.count;
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray*tempary= dataary[section];
    return tempary.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
  
    static NSString *ID = @"SettingCell";
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb1.text=dataary[indexPath.section][indexPath.row];
    if (indexPath.section==0&&indexPath.row==4) {
        NSString *cacheSize = [ClearCacheTool getCacheSize];
        cell.lb1.text = [NSString stringWithFormat:@"当前缓存大小(%@) 点击清除",cacheSize];
    }
    
    if (indexPath.section==1) {
        cell.lb1.hidden=YES;
        cell.hidenlb.hidden=NO;
        cell.accessoryType=UITableViewCellAccessoryNone;
    }
    return cell;
}
#pragma mark 设置分组头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}


#pragma mark 设置尾部说明内容高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}

#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 64;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    if (indexPath.row==0&&indexPath.section==0) {
            IDAuthViewController *IDAuthVC = [[IDAuthViewController alloc] init];
            [self.navigationController pushViewController:IDAuthVC animated:YES];
       
    }
    
    
      if (indexPath.section==0&&indexPath.row==4) {
          BOOL isClearSuccess = [ClearCacheTool clearCaches];
          SettingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
          if (isClearSuccess) {
              [WSProgressHUD showImage:nil status:@"清除成功"];
              NSString *cacheSize = [ClearCacheTool getCacheSize];
              cell.lb1.text = [NSString stringWithFormat:@"当前缓存大小(%@) 点击清除",cacheSize];
          }else{
              [WSProgressHUD showImage:nil status:@"清除失败"];
          }
      }else
      {
           [MyUtils collviewSelidex:dataary[indexPath.section][indexPath.row]  toVc:self andShopInfo:nil];
      }
    
    if (indexPath.section==1) {
        [FuncPublic SaveDefaultInfo:@"" Key:@"token"];
        [FuncPublic SaveDefaultInfo:@"" Key:@"myphone"];
        self.tabBarController.selectedIndex=0;
        [self.navigationController popToRootViewControllerAnimated:YES];
    }

}

@end
